<template>
  <footer class="footer">
    <span class="todo-count" v-show="leftList !== 0"
      ><strong>{{ leftList }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          href="#/"
          @click.prevent="filter('all')"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'active' }"
          href="#/"
          @click.prevent="filter('active')"
          >进行中</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'completed' }"
          href="#/"
          @click.prevent="filter('completed')"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clearList">清除已完成</button>
  </footer>
</template>

<script>
export default {
  name: 'TodoFooter',
  props: {
    list: {
      type: Array,
      required: true
    },
    type: {
      type: String,
      required: true
    }
  },
  methods: {
    clearList () {
      this.$emit('clearList')
    },
    changeType (type) {
      this.$emit('changeType', type)
    },
    filter (type) {
      this.$emit('filter', type)
    }
  },
  computed: {
    leftList () {
      return this.list.filter(item => item.isDone === false).length
    }
  }
}
</script>

<style scoped lang="less"></style>
